<template>
	<view>
		<template v-if="list.length>0">
			<block v-for="(item,index) in list" :key="index">
				<index-list :item="item" :index="index"></index-list>
			</block>
			<load-more :loadtext="loadtext"></load-more>
		</template>
		<template v-else-if="issearch && list.length<1">
			<nothing></nothing>
		</template>

	</view>
</template>

<script>
	import indexList from "../../components/index/index-list.vue";
	import nothing from "../../components/common/nothing.vue";
	import loadMore from "../../components/common/load-more.vue";

	export default {
		components: {
			indexList,
			nothing,
			loadMore
		},
		data() {
			return {
				searchtext:"",
				issearch:false,
				loadtext: "上拉加载更多",
				list: []
			}
		},
		// 监听原生标题栏按钮的点击事件
		onNavigationBarButtonTap(e) {
			
			if (e.index == 0) {
				this.getdata()
			}
		},
		// 监听原生标题栏搜索输入框输入内容变化事件
		onNavigationBarSearchInputChanged(e) {
			this.searchtext=e.text;
		},
		// 监听原生标题栏搜索输入框搜索事件，用户点击软键盘上的“搜索”按钮时触发。
		onNavigationBarSearchInputConfirmed(e) {
			if(e.text){
				this.getdata()
			}
		},
		// 监听页面触底时间
		onReachBottom() {
			this.loadmore()
		},
		// 监听下拉刷新
		onPullDownRefresh(){
			this.getdata();
			uni.stopPullDownRefresh()
		},
		methods: {
			// 搜索事件
			getdata() {
				uni.showLoading();
				// 请求服务器 post keyword：val
				setTimeout(() => {
					let arr = [
						{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							isguanzhu: false,
							title: "我是标题",
							type: "img", //img，图文，video，视频
							titlepic: "../../static/demo/datapic/1.jpg",
							infonum: {
								index: 0, //0没有操作，1 已经顶了 2 已经踩了
								dingnum: 11,
								cainum: 11,
							},
							commentnum: 10,
							sharenum: 10
						},
						{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							isguanzhu: true,
							title: "我是标题",
							type: "video", //img，图文，video，视频
							titlepic: "../../static/demo/datapic/1.jpg",
							playnum: "20w",
							long: 2.47,
							infonum: {
								index: 1, //0没有操作，1 已经顶了 2 已经踩了
								dingnum: 11,
								cainum: 11,
							},
							commentnum: 10,
							sharenum: 10
						},
						{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							isguanzhu: true,
							title: "我是标题",
							type: "video", //img，图文，video，视频
							titlepic: "../../static/demo/datapic/1.jpg",
							playnum: "20w",
							long: 2.47,
							infonum: {
								index: 1, //0没有操作，1 已经顶了 2 已经踩了
								dingnum: 11,
								cainum: 11,
							},
							commentnum: 10,
							sharenum: 10
						}
					];
					this.list = arr;
					uni.hideLoading()
					this.issearch=true;
				}, 1000);
			},

			// 上拉加载
			loadmore() {
				if (this.loadtext != "上拉加载更多") {
					return;
				}
				// 修改状态（加载状态）
				this.loadtext = "加载中"
				// 获取数据
				setTimeout(() => {
					// 获取完成状态
					// 一条模拟数据
					let obj = {
						userpic: "../../static/demo/userpic/3.jpg",
						username: "昵称",
						isguanzhu: true,
						title: "我是标题",
						type: "video", //img，图文，video，视频
						titlepic: "../../static/demo/datapic/3.jpg",
						playnum: "20w",
						long: 2.47,
						infonum: {
							index: 1, //0没有操作，1 已经顶了 2 已经踩了
							dingnum: 11,
							cainum: 11,
						},
						commentnum: 10,
						sharenum: 10
					};
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
				}, 1000);
				// this.loadtext="到底了"
			}


		}
	}
</script>

<style>

</style>
